﻿using System;
using System.Windows.Forms;
using Main.Forms;
using Microsoft.VisualBasic.ApplicationServices;
using Pharmacy.Data;

namespace Pharmacy
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();

            //DevExpress.Skins.SkinManager.EnableFormSkinsIfNotVista();
            //---HCM
            //ServiceFacade.SettingsHelper.OfficeAddress = "65 Nguyễn Du, Quận 1, TP. Hồ Chí Minh ; Tel: 84-8-3829 8424";
            //ServiceFacade.SettingsHelper.ClinicAddress =
            //    "Phòng khám ( HCM Clinic) : 167 Nam Kỳ Khởi Nghĩa, Quận 3, TP.HCM";
            //ServiceFacade.SettingsHelper.TaxCode = "3 5 0 0 1 0 6 4 4 0 - 0 0 1";
            //---HAN
            //ServiceFacade.SettingsHelper.OfficeAddress = "51 Xuân Diệu, Quận Tây Hồ, Hà Nội ; Tel: 84-4-3934 0666";
            //ServiceFacade.SettingsHelper.ClinicAddress =
            //    Phòng khám ( HN Clinic) : 01 Đặng Thái Mai, Quận Tây Hồ, Hà Nội;
            //ServiceFacade.SettingsHelper.TaxCode = "3 5 0 0 1 0 6 4 4 0 - 0 0 2";
            //---VTU
            //ServiceFacade.SettingsHelper.OfficeAddress = "";
            //ServiceFacade.SettingsHelper.ClinicAddress =
            //     01 Lê Ngọc Hân, TP. Vũng Tàu  ; Tel: 84-64-3858 776;
            //ServiceFacade.SettingsHelper.TaxCode = "3 5 0 0 1 0 6 4 4 0";

            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.UserSkins.BonusSkins.Register();

            DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.OfficeSkins).Assembly);
            DevExpress.Skins.SkinManager.Default.RegisterAssembly(typeof(DevExpress.UserSkins.BonusSkins).Assembly);

            //Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
            Application.SetCompatibleTextRenderingDefault(false);
            new MyApp().Run(new string[] { });
            //Application.Run(new MiniSkin());
        }
        public static Entities.WebUser GlobalUser;
        public static MiniSkin MainForm;
        public class MyApp : WindowsFormsApplicationBase
        {
            //protected override void OnCreateSplashScreen()
            //{
            //    var loading = new Loading();
            //    //loading.UpdateProgress();
            //    SplashScreen = loading;
            //}

            protected override void OnCreateMainForm()
            {
                // Do your initialization here
                //...
                //System.Threading.Thread.Sleep(4000);  // Test
                // Then create the main form, the splash screen will automatically close
                //Utility.MyFunction = new Utility.RunFunction(GetGlobalUser);
                //Utility.ShowErrorForm();
                
                // Set Skin
                //UserLookAndFeel.Default.SetSkinStyle("Coffee");

                // Ensure that the Office2003 painting scheme will be used. 
                string username = SystemInformation.UserName;
                //ServiceFacade.SettingsHelper.GridPageSize=10;
                GlobalUser = DataRepository.WebUserProvider.GetByUserId(username);

                if (GlobalUser == null)
                    this.MainForm = new AccessDenied();
                else
                {
                    Program.MainForm = new MiniSkin();
                    MainForm = Program.MainForm;
                }
            }
        }
    }
}
